﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace System.Web.Mvc.Html
{
    public static class PagingHelper
    {
        public static string Paging(this HtmlHelper helper, int pIntPage, int pIntNumberRecordPerPage, int pIntTotalRecord)
        {
            int intNumberPage = 0;
            if (pIntTotalRecord % pIntNumberRecordPerPage == 0)
            {
                intNumberPage = (pIntTotalRecord / pIntNumberRecordPerPage);
            }
            else
            {
                intNumberPage = (pIntTotalRecord / pIntNumberRecordPerPage) + 1;
            }
            if (pIntTotalRecord == 0) intNumberPage = 1;

            List<string> vObjPage = new List<string>();
            for (int i = 1; i <= intNumberPage; i++)
            {
                vObjPage.Add(i.ToString());
            }
            string[] vArrPage = vObjPage.ToArray();

            string strHtml = "<table border=\"0\" style=\"width:auto\" cellpadding=\"0\" cellspacing=\"0\">";
            strHtml = strHtml + "<tr>";
            strHtml = strHtml + "<td><input type=\"button\" name=\"btnFirstPage\" class=\"move_first\" onclick=\"btnFirstPageOnclick('Page');\"/></td>";
            strHtml = strHtml + "<td><input type=\"button\" name=\"btnPrePag\" class=\"move_previous\" onclick=\"btnPrePageOnclick('Page');\" /></td>";
            strHtml = strHtml + "<td>" + helper.DropDownList("Page", new SelectList(vArrPage), new { onchange = "btnPageOnclick();" }) + "</td>";
            strHtml = strHtml + "<td><input type=\"button\" name=\"btnNextPage\" class=\"move_next\" onclick=\"btnNextPageOnclick('Page');\" /></td>";
            strHtml = strHtml + "<td><input type=\"button\" name=\"btnLastPage\" class=\"move_last\" onclick=\"btnLastPageOnclick('Page');\" /></td>";
            strHtml = strHtml + "<td>" + helper.DropDownList("NumerRecordPerPage", new SelectList(new[] { "10", "15", "20", "30", "40", "50" }), new { onchange = "btnNumerRecordPerPageOnclick();" }) + "</td>";
            strHtml = strHtml + "</tr>";
            strHtml = strHtml + "</table>";
            return strHtml;
        }
    }
}

